import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class MapTest {
    public static void main(String[] args) {
        //定义
        TreeMap<String, Integer> map = new TreeMap<>();
        HashMap<String, Integer> map1 = new HashMap<>();
        Map<String, Integer> map2 = new TreeMap<>();
        Map<String, Integer> map3 = new HashMap<>();
        //put(key, val)设置key对应的value
        map.put("sunny", 3);
        map.put("the",5);
        map.put("hello",2);
        map.put("hello",21);

        //get(key) 获取key对应的val
        System.out.println(map.get("the"));

        //getOrDefault(key, default) 获取key值对应的val, key不存在返回默认值
        System.out.println(map.getOrDefault("hello",6666));
        System.out.println(map.getOrDefault("H", 6666));

        //remove(key) 删除key对应的映射关系
        map.remove("the");
        System.out.println(map.getOrDefault("the", 6666));

        //keySet() 返回所有key的不重复集合
        System.out.println(map.keySet());

        //values() 返回所有value的可重复集合
        System.out.println(map.values());

        //entrySet() 返回所有key - value映射关系
        System.out.println(map.entrySet());

        //containsKes(key) 判断是否包含key
        System.out.println(map.containsKey("the"));

        //containsValue(val) 判断value
        System.out.println(map.containsValue(666));

    }
}
